{include file="layout/head"}
<body class="fixed-sidebar  gray-bg " style="overflow:hidden">
<div id="wrapper">
    <!--左侧导航开始-->
    <nav class="navbar-default navbar-static-side" role="navigation">
        <div class="nav-close"><i class="fa fa-times-circle"></i></div>
        <div class="sidebar-collapse">
            <ul class="nav" id="side-menu">
                <li class="nav-header">
                    <div class="dropdown profile-element">
                        <a data-toggle="dropdown" class="dropdown-toggle" href="#">
                            <span class="clear">
                                <span class="block m-t-xs" style="font-size:18px;">
                                <strong class="font-bold">{$sys_config.main_title}</strong>
                                </span>
                            </span>
                        </a>
                    </div>
                    <div class="logo-element">{$sys_config.main_title}</div>
                </li>
                <li class="line dk"></li>
                {$menu_view}
            </ul>
        </div>
    </nav>
    <!--左侧导航结束-->
    <!--右侧部分开始-->
    <div id="page-wrapper" class="gray-bg dashbard-1">
        <div class="row border-bottom">
            <nav class="navbar navbar-static-top" role="navigation" style="margin-bottom: 0">
                <div class="navbar-header">
                    <a class="navbar-minimalize minimalize-styl-2" href="#" title="展示收起侧栏">
                        <i class="fa fa-outdent"></i>
                    </a>
                </div>
                <div class="navbar-module">
                    {$sys_config.top_links}
                </div>
                <ul class="nav navbar-top-links navbar-right">
                    <li>
                        <a href="{:url('admin/Store/apps')}" class="J_menuItem" target="_blank">
                        <i class="fa fa-fire"></i>应用</a></li>
                    <li>
                        <a href="http://www.07fly.xyz/" target="_blank"><i class="fa fa-home"></i>官网</a>
                    </li>
                    <li class="dropdown">
                        <a class="dropdown-toggle count-info" data-toggle="dropdown" href="#">
                            <i class="fa fa-chevron-down">{$sys_user_info['realname']}</i> </a>
                        <ul class="dropdown-menu dropdown-alerts">
                            <li>
                                <a data-url="{:url('SysUser/editInfo',array('id'=>$sys_user_info['id']))}"
                                   class="ajax-open" title="个人资料" data-calback="window.location.reload();">
                                    <div><i class="fa fa-envelope fa-fw"></i> 个人资料</div>
                                </a>
                            </li>
                            <li class="divider"></li>
                            <li>
                                <a href="{:url('SysUser/editPwd',array('id'=>$sys_user_info['id']))}" class="ajax-open"
                                   title="个人资料">
                                    <div><i class="fa fa-qq fa-fw"></i> 密码修改</div>
                                </a>
                            </li>
                            <li class="divider"></li>
                            <li>
                                <div class="text-center link-block">
                                    <a class="ajax-get" href="{:url('Login/logout')}"  data-calback="window.location.reload();">
                                    <strong>退出登录 </strong> <i class="fa fa-angle-right"></i>
                                    </a>
                                </div>
                            </li>
                        </ul>
                    </li>
                </ul>
            </nav>
        </div>
        <div class="row J_mainContent" id="content-main">
            <iframe id="J_iframe" width="100%" height="95%" src="{:url('Index/main')}" frameborder="0"
                    data-id="index_v1.html" seamless></iframe>
        </div>
    </div>
    <!--右侧部分结束-->
</div>

{include file="layout/bottom"}
<script>
    $(".navbar-module a").click(function () {
        $(this).addClass("on");
        $(this).siblings().removeClass('on');
    });
    $(document).ready(function () {
        var iframeUrl = localStorage.getItem('iframeUrl');
        if (typeof (iframeUrl) != "undefined" && iframeUrl != null) {

        } else {
            iframeUrl = "{:url('Index/main')}";
        }
        document.onkeypress = function (e) {
            if (e.keyCode == 116) {
                e.preventDefault(); //组织默认刷新
                iframe.src = iframeUrl;
            }
        }
        //刷新时设置当前点击页面数据
        if (typeof (iframeUrl) != "undefined") {
            that = $("a[href='" + iframeUrl + "']");
            //that.parent('li').addClass('active');
            that.parents('ul.nav').addClass('in');
            that.parents('ul.nav').parent('li').addClass('active');
            $('#J_iframe').attr('src', iframeUrl);//重新设置获取的url，实现刷新显示当前页面
        }

        //保存点击
        $(".J_menuItem").on('click', function () {
            var itemUrl = $(this).attr('href');
            console.log(iframeUrl);
            localStorage.setItem('iframeUrl', itemUrl);
        });
    });


    //声音播放插件
    var playSound = function () {
        var borswer = window.navigator.userAgent.toLowerCase();

        var num = Math.floor(Math.random() * 6) + 1;

        var video = "__STATIC__/module/admin/img/" + num + ".wav";

        if (borswer.indexOf("ie") >= 0) {
            //IE内核浏览器
            var strEmbed = '<embed name="embedPlay" src="' + video + '" autostart="true" hidden="true" loop="false"></embed>';
            if ($("body").find("embed").length <= 0)
                $("body").append(strEmbed);
            var embed = document.embedPlay;

            //浏览器不支持 audion，则使用 embed 播放
            embed.volume = 100;
            //embed.play();这个不需要
        } else {
            //非IE内核浏览器
            var strAudio = "<audio id='audioPlay' src='" + video + "' hidden='true'>";
            if ($("#audioPlay").length <= 0) {
                $("body").append(strAudio);
            }
            var audio = document.getElementById("audioPlay");
            //浏览器支持 audio
            audio.play();
        }

        log(video);

    }

    //提示通知插件
    var playNotice = function (id, title, content, url = '') {
        toastr.options = {
            "closeButton": true,
            "debug": false,
            "progressBar": true,
            "positionClass": "toast-bottom-right",
            "onclick": null,
            "showDuration": "400",
            "hideDuration": "1000",
            "timeOut": "20000",
            "extendedTimeOut": "1000",
            "showEasing": "swing",
            "hideEasing": "linear",
            "showMethod": "fadeIn",
            "hideMethod": "fadeOut"
        }
        //点击事件
        toastr.options.onclick = function () {
            layer.open({
                type: 2,
                title: '查看通知',
                shadeClose: true,
                fixed: false, //不固定
                area: ['90%', '90%'],
                content: url
            });
        };

        toastr.info(content, title);

    }


    //提示通知插件
    var runSysMsg = function () {

        var target = "{:url('admin/SysMsg/show_json',array('deal_user_id'=>$sys_user_info.id,'deal_status'=>0,'remind_sys'=>1))}";//显示系统通知
        var detail = "{:url('admin/OaNotify/main_json')}";

        $.ajax({
            type: 'POST',
            url: target,
            data: '',
            dataType: 'json',
            success: function (jsonData) {

                $(jsonData.data).each(function (index, item) {
                    playNotice(item.id, '系统提醒', item.bus_name, item.bus_url);
                });

                if (jsonData.data.length > 0) {
                    playSound();
                }
            }
        });
    }

    //系统公告
    var runSysNotify = function () {
        var target = "{:url('admin/OaNotify/main_json',array('owner_user_id'=>$sys_user_info.id,'read_state'=>0))}";
        var detail = "{:url('admin/OaNotify/main_json')}";
        $.ajax({
            type: 'POST',
            url: target,
            data: {"status": "-1"},
            dataType: 'json',
            success: function (jsonData) {
                $(jsonData.data).each(function (index, item) {
                    playNotice(item.id, '系统公告', item.name, detail + '?id=' + item.id);
                });
                if (jsonData.data.length > 0) {
                    playSound();
                }
            }
        });
    }

    //系统计划执行消息
    var runScanSysMsg = function () {
        var target = "{:url('admin/SysMsgType/scanbus')}";
        $.ajax({
            type: 'GET',
            url: target,
            dataType: 'json',
            success: function (jsonData) {

            }
        });
    }

    //主动调用
    //setInterval("func()", 60000);
    setInterval("runSysNotify()", 1000 * 60 * 5);
    setInterval("runSysMsg()", 1000 * 60 * 10);

    runScanSysMsg();
    runSysNotify();
    runSysMsg();
</script>

